self.orig_files.append('/'.join([x[0] for x in path]))
r.append(([(self._to_fs_2(u), u, o) for u, o in path], i))
i += 1
# If two or more file/subdirectory names in the same directory
# would map to the same name after encoding conversions + Windows
# workarounds, change them. Files are changed as
# 'a.b.c'->'a.b.0.c', 'a.b.1.c' etc, directories or files without
# '.' as 'a'->'a.0', 'a.1' etc. If one of the multiple original
# names was a "clean" conversion, that one is always unchanged
# and the rest are adjusted.
r.sort()
self.files_fs = [None] * len(r)
prev = [None]
res = []
stack = [{}]
for x in r:
j = 0
x, i = x
while x[j] == prev[j]:
j += 1
del res[j:]
del stack[j+1:]
name = x[j][0][1]
if name in stack[-1]:
for name in generate_names(x[j][1], j != len(x) - 1):
name = self._to_fs(name)
if name not in stack[-1]:
break
stack[-1][name] = None
res.append(name)
for j in range(j + 1, len(x)):
name = x[j][0][1]
stack.append({name: None})
res.append(name)
self.files_fs[i] = os.path.join(*res)
prev = x
self.name = self._get_field_utf8(info, 'name')
self.name_fs = self._to_fs(self.name)
self.piece_length = info['piece length']
self.announce = metainfo['announce']
self.hashes = [info['pieces'][x:x+20] for x in xrange(0,
len(info['pieces']), 20)]
self.infohash = sha(bencode(info)).digest()
def show_encoding_errors(self, errorfunc):
self.reported_errors = True
if self.bad_torrent_unsolvable:
errorfunc(ERROR, "This .torrent file has been created with a broken tool and has incorrectly encoded filenames. Some or all of the filenames may appear different from what the creator of the .torrent file intended.")
elif self.bad_torrent_noncharacter:
errorfunc(ERROR, "This .torrent file has been created with a broken tool and has bad character values that do not correspond to any real character. Some or all of the filenames may appear different from what the creator of the .torrent file intended.")
elif self.bad_torrent_wrongfield:
errorfunc(ERROR, "This .torrent file has been created with a broken tool and has incorrectly encoded filenames. The names used may still be correct.")
elif self.bad_conversion:
errorfunc(WARNING, 'The character set used on the local filesystem ("'+filesystem_encoding+'") cannot represent all characters used in the filename(s) of this torrent. Filenames have been changed from the original.')
elif self.bad_windows:
errorfunc(WARNING, 'The Windows filesystem cannot handle some characters used in the filename(s) of this torrent. Filenames have been changed from the original.')
elif self.bad_path:
errorfunc(WARNING, "This .torrent file has been created with a broken tool and has at least 1 file with an invalid file or directory name. However since all such files were marked as having length 0 those files are just ignored.")
# At least BitComet seems to make bad .torrent files that have
# fields in an arbitrary encoding but separate 'field.utf-8' attributes